import { Tabs } from 'nextra/components';

# Getting started with the Command Line Interface (CLI)

## Setup

The CLI can be used directly, installed globally, or installed in any project as
a dependency.

### No installation

In order to use it directly any of these commands will work:

<Tabs items={["npx", "pnpm", "yarn"]}>
  <Tabs.Tab>

```shell filename="Terminal" copy
npx @react-docgen/cli --help
```

  </Tabs.Tab>
  <Tabs.Tab>

```shell filename="Terminal" copy
pnpm dlx @react-docgen/cli --help
```

  </Tabs.Tab>
  <Tabs.Tab>

```shell filename="Terminal" copy
yarn dlx @react-docgen/cli --help
```

  </Tabs.Tab>
</Tabs>

### Install

Installing the CLI can be done with any available package manager:

<Tabs items={["npm", "pnpm", "yarn"]}>
  <Tabs.Tab>

```shell filename="Terminal" copy
npm install --save @react-docgen/cli
```

  </Tabs.Tab>
  <Tabs.Tab>

```shell filename="Terminal" copy
pnpm add @react-docgen/cli
```

  </Tabs.Tab>
  <Tabs.Tab>

```shell filename="Terminal" copy
yarn add @react-docgen/cli
```

  </Tabs.Tab>
</Tabs>

## Usage

For basic usage, you need to provide a glob or path to a file that includes a
react component. The result will be printed to the `stdout` and in case there
are errors or warnings while analyzing the file, these will be printed to
`stderr`.

The result will be an array of [Documentation](../reference/documentation/basic.mdx)
objects, stringified to JSON.

```shell filename="Terminal" copy
react-docgen ./src/components/Button.tsx
```

Multiple files can be analyzed at once

```shell filename="Terminal" copy
react-docgen ./src/components/Button.tsx ./src/components/Label.tsx
```

Or a glob can be used to include multiple files

```shell filename="Terminal" copy
react-docgen ./src/components/**/*.tsx
```

The output can be written into a file instead of directly outputting it.
Warnings and errors will still be written to `stderr`.

```shell filename="Terminal" copy
react-docgen -o output.json ./src/components/Button.tsx
```

The CLI supports a lot more advanced options and for a full list checkout the
[reference page](../reference/cli)
